package day1212_3;


class   P2  extends  Thread{
    Object pool;//水池
    public void run() {
        System.out.println("放入水");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        synchronized (pool){
            pool.notify();
        }
    }
}



class   P1  extends  Thread{
    Object pool;//水池
    public void run() {
        synchronized (pool){
            try {
                pool.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("取水");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}




public class T2 {
    public static void main(String[] args) {
        Object suo=new Object();
        P1  person1=new P1();  person1.pool=suo;  person1.start();
        P2  person2=new P2();  person2.pool=suo;  person2.start();
    }
}

